<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="x::head('客服专员工单')" />
<script type="text/javascript">
    $(function() {
        // “超级管理员、管理员”有客服专员查询条件
        if (g_roleType == "A" || g_roleType == "M") {
            $("#td_cs_title").show();
            $("#td_cs_content").show();
        } else {
            $("#td_cs_title").hide();
            $("#td_cs_content").hide();
        }

        $('#dg').datagrid({
            url : 'form/qryForPage?formMenuType=3',
            fit : true,
            selectOnCheck : false,
            toolbar : '.dgtoolbar',
            onClickRow : function(i, r) {
                $('#dg').datagrid('clearSelections');
                $('#dg').datagrid('checkRow', i);
                checkBnt();
            },
            onCheck : checkBnt,
            onUncheck : checkBnt,
            onCheckAll : checkBnt,
            onUncheckAll : checkBnt,
            onLoadSuccess : function(i, r) {
                $("#feedbackSupplierBnt, #closeBnt, #viewBnt, #exportBnt").linkbutton('disable');
            }
        });
    });

    function checkBnt() {
        $("#feedbackSupplierBnt, #closeBnt, #viewBnt, #exportBnt").linkbutton('disable');
        var rows = $('#dg').datagrid('getChecked');
        if (rows.length == 1) {
            $("#feedbackSupplierBnt, #closeBnt, #viewBnt, #exportBnt").linkbutton('enable');
        } else if (rows.length > 1) {
            var flag = true;
            for (var i = 0; i < rows.length; i++) {
                if ($.inArray(rows[i].vendorFormStatus, [ 2, 3, 4 ]) > -1) {
                    flag = false;
                }
            }
            if (flag) {
                $("#feedbackSupplierBnt").linkbutton('enable');
            } else {
                $("#feedbackSupplierBnt").linkbutton('disable');
            }
        }
    }

    function doSearch() {
        $('#qryFrmDiv').qryFormDialog({
            dg : 'dg'
        });
    }

    function closed() {
        var dlg = $("#ww-closed");
        var frm = dlg.find("form");
        var std = $('#dg').datagrid("getChecked")[0];
        var _complaintId = std.complaintId;
        frm.find("input[name=complaintId]").val(_complaintId);

        $.post('panel/vendorcpt/qryForList', {
            complaintId : _complaintId
        }, function(rs) {
            $("#logRemark2").textbox("setValue", rs[0].remark);
        }, 'json');

        dlg.dialog({
            title : '关闭供应商流程',
            toolbar : [ {
                text : bnt_save,
                iconCls : 'icon-save',
                handler : function() {
                    frm.form('submit', {
                        success : function(rs) {
                            var json = $.parseJSON(rs);
                            if (json.code) {
                                tipSuccess();
                                dlg.dialog('close');
                                $('#dg').datagrid('reload');
                            } else {
                                tipFail(json.data);
                            }
                        }
                    });
                }
            }, rebackBnt(dlg) ],
            onClose : function() {
                frm.form('reset');
            }
        }).dialog('center').dialog('open');
    }

    function view() {
        var dlg = $('#csCptView');
        var std = $('#dg').datagrid("getChecked")[0];
        var _complaintId = std.complaintId;
        var _status = std.status;
        dlg.find("input,textarea").attr("disabled", true);
        $("#remark", dlg).textbox('textbox').attr("disabled", false);

        $.post('form/edit', {
            complaintId : _complaintId
        }, function(rs) {
            setViewValue(dlg, rs);
            editAfterImg('frmView');

            showSolution();
            createDownLoadA(dlg.find("#reimAppScanFileTd"), dlg.find("input[name=reimAppScanFile]").val());

            $('#dg-suplier').datagrid({
                url : 'panel/cscpt/qryVendorChg?complaintId=' + _complaintId
            });
            $('#dg-suplierConfirmLog').datagrid({
                url : 'panel/vendorcpt/qryForList?complaintId=' + _complaintId
            });
            $('#dg-formlog').datagrid({
                url : 'form/qryFormLog?complaintId=' + _complaintId
            });

            dlg.dialog({
                title : '[[#{panel.form.cs}]]-[[#{view}]]',
                maximized : true,
                onOpen : function() {
                    dlg.find(".easyui-tabs").tabs('select', 0);
                }
            }).dialog('center').dialog('open');
        }, 'json');
    }

    // 批量反馈供应商
    function feedbackSupplier() {
        var dlg = $('#ww-feedback-suplier');
        var frm = dlg.find("form");
        var ids = [];
        var rows = $('#dg').datagrid("getChecked");
        for (var i = 0; i < rows.length; i++) {
            ids.push(rows[i].complaintId);
        }
        frm.find("[name=ids]").val(ids.join(","));

        dlg.dialog({
            title : '[[#{bnt.feedback.supplier}]]',
            toolbar : [ {
                text : bnt_save,
                iconCls : 'icon-save',
                handler : function() {
                    if (!frm.form('validate')) {
                        return;
                    }
                    frm.form('submit', {
                        success : function(rs) {
                            var json = $.parseJSON(rs);
                            if (json.code) {
                                tipSuccess();
                                dlg.dialog('close');
                                $('#dg').datagrid('reload');
                            } else {
                                tipFail(json.data);
                            }
                        }
                    });
                }
            }, rebackBnt(dlg) ],
            onClose : function() {
                frm.form('reset');
            }
        }).dialog('center').dialog('open');
    }

    function excelExport() {
        window.open('panel/cscpt/excelExport?complaintId=' + $('#dg').datagrid("getChecked")[0].complaintId);
    }

    function batchExcelExport() {
        window.open('panel/cscpt/batchExcelExport?formMenuType=3&' + $('#qryFrmDiv form').serialize());
    }
</script>

<body>
	<div th:replace="x::loading" />
	<div class="dgtoolbar">
		<shiro:hasPermission name="cscpt:feedbackSupplier">
			<a id="feedbackSupplierBnt" class="easyui-linkbutton" data-options="iconCls:'icon-confirm'" onclick="feedbackSupplier()" th:text="#{bnt.feedback.supplier}">反馈供应商</a>
		</shiro:hasPermission>
		<shiro:hasPermission name="cscpt:closedVendorFormStatus">
			<a id="closeBnt" class="easyui-linkbutton" data-options="iconCls:'icon-closed'" onclick="closed()">关闭</a>
		</shiro:hasPermission>
		<a id="viewBnt" class="easyui-linkbutton" data-options="iconCls:'icon-view'" onclick="view()" th:text="#{bnt.view}">查看</a>
		<a class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="doSearch()" th:text="#{bnt.qry}">查询</a>
		<a id="exportBnt" class="easyui-linkbutton" data-options="iconCls:'icon-excel'" onclick="excelExport()" th:text="#{bnt.export}">导出</a>
		<a class="easyui-linkbutton easyui-tooltip" data-options="iconCls:'icon-excel'" title="按“查询条件”批量导出" onclick="batchExcelExport()" th:text="#{bnt.batchExport}">批量导出</a>
	</div>

	<table id="dg" border="0">
		<thead>
			<tr>
				<th data-options="field:'ck',checkbox:true" />
				<th data-options="field:'complaintNo',width:'12%'" th:text="#{complaintNo}">客诉单号</th>
				<th data-options="field:'statusName',width:'22%'" th:text="#{status}">状态</th>
				<th data-options="field:'vendorFormStatusName',width:'15%'" th:text="#{vendor.form.status}">供应商工单状态</th>
				<th data-options="field:'priorityName',width:'8%'" th:text="#{priority}">优先级</th>
				<th data-options="field:'feedbackCsTime',width:'15%'" th:text="#{feedback.cs.time}">反馈客服时间</th>
				<th data-options="field:'curInitialType',width:'15%'" th:text="#{initial.type}">初审意见类型</th>
				<th data-options="field:'solutionType',width:'13%'" th:text="#{solution.type}">解决方案类型</th>
				<th data-options="field:'orderNo',width:'10%'" th:text="#{orderNo}">订单号</th>
				<th data-options="field:'movement',width:'10%'" th:text="#{chassis}">机芯</th>
				<th data-options="field:'ourModel',width:'13%'" th:text="#{ourModel}">我司型号</th>
				<th data-options="field:'custModel',width:'13%'" th:text="#{custModel}">买家型号</th>
				<th data-options="field:'badPhase',width:'7%'" th:text="#{bad.phase}">不良阶段</th>
				<th data-options="field:'screen',width:'15%'" th:text="#{screen}">配屏</th>
				<th data-options="field:'failureType',width:'25%'" th:text="#{phenomenon.type}">故障现象类型</th>
				<th data-options="field:'createUserName',width:'35%'" th:text="#{cust.name}">客户名称</th>
				<th data-options="field:'createTime',width:'15%'" th:text="#{createTime}">创建时间</th>
			</tr>
		</thead>
	</table>


	<!-- 查询条件 -->
	<div id="qryFrmDiv" class="easyui-dialog dlgForm2" data-options="height:500,closed:true">
		<form>
			<table class="qryTable">
				<tr>
					<td th:text="#{complaintNo}">客诉单号</td>
					<td>
						<input class="easyui-textbox" name="complaintNo">
					</td>
					<td th:text="#{vendor.form.status}">供应商工单状态</td>
					<td>
						<input class="easyui-combobox" name="vendorFormStatus" data-options="url:'console/sys/dict/selectDictEx/1113/5',panelHeight:'auto'">
					</td>
				</tr>
				<tr>
					<td th:text="#{initial.type}">初审意见类型</td>
					<td>
						<input class="easyui-combobox" name="curInitialType" data-options="url:'console/sys/dict/selectDict/1111',panelHeight:'auto'">
					</td>
					<td th:text="#{solution.type}">解决方案类型</td>
					<td>
						<input class="easyui-combobox" name="solutionType" data-options="url:'console/sys/dict/selectDict/1112',panelHeight:'auto'">
					</td>
				</tr>
				<tr>
					<td th:text="#{phenomenon.type}">故障现象类型</td>
					<td>
						<input class="easyui-combobox" name="failureType" data-options="url:'console/sys/dict/selectDict/1102',panelHeight:300">
					</td>
					<td th:text="#{suplier.code}">供应商账号</td>
					<td>
						<input class="easyui-combobox" name="vendorCode" data-options="valueField:'vendorCode',textField:'vendorName',url:'archives/vendor/selectVendor?isValid=1',panelHeight:300">
					</td>
				</tr>
				<tr>
					<td th:text="#{feedback.cs.time.start}">反馈客服时间(始)</td>
					<td>
						<input class="Wdate" id="feedbackCsTimeStart" name="feedbackCsTimeStart" onfocus="WdatePicker({isShowClear:true,readOnly:true,maxDate:'%y-%M-%d'})">
					</td>
					<td th:text="#{feedback.cs.time.end}">反馈客服时间(止)</td>
					<td>
						<input class="Wdate" id="feedbackCsTimeEnd" name="feedbackCsTimeEnd" onfocus="WdatePicker({isShowClear:true,readOnly:true,minDate:'#F{$dp.$D(\'feedbackCsTimeStart\')}',maxDate:'%y-%M-%d'})">
					</td>
				</tr>
				<tr>
					<td th:text="#{bad.phase}">不良阶段</td>
					<td>
						<input class="easyui-combobox" name="badPhase" data-options="url:'console/sys/dict/selectDict/1001',panelHeight:'auto'">
					</td>
					<td th:text="#{part.name}">部件名称</td>
					<td>
						<input class="easyui-combobox" name="partName" data-options="url:'console/sys/dict/selectDict/1104',panelHeight:300">
					</td>
				</tr>
				<tr>
					<td th:text="#{panel.module.model}">屏体模组型号</td>
					<td>
						<input class="easyui-textbox" name="panelModuleModel">
					</td>
					<td th:text="#{panel.module.sn}">屏体模组序列号</td>
					<td>
						<input class="easyui-textbox" name="panelModuleSn">
					</td>
				</tr>
				<tr>
					<td th:text="#{oc.model}">玻璃型号</td>
					<td>
						<input class="easyui-textbox" name="ocModel">
					</td>
					<td th:text="#{oc.pcbi.sn}">玻璃序列号</td>
					<td>
						<input class="easyui-textbox" name="ocSn">
					</td>
				</tr>
				<tr>
					<td th:text="#{orderNo}">订单号</td>
					<td>
						<input class="easyui-textbox" name="orderNo">
					</td>
					<td th:text="#{cust.name}">客户名称</td>
					<td>
						<input class="easyui-textbox" name="custName">
					</td>
				</tr>
				<tr>
					<td th:text="#{orderType}">订单类型</td>
					<td>
						<input class="easyui-textbox" name="orderType">
					</td>
					<td th:text="#{brand}">品牌</td>
					<td>
						<input class="easyui-textbox" name="brand">
					</td>
				</tr>
				<tr>
					<td th:text="#{chassis.model}">机芯\机型</td>
					<td>
						<input class="easyui-textbox" name="movementModel">
					</td>
					<td th:text="#{chassis}">机芯</td>
					<td>
						<input class="easyui-textbox" name="movement">
					</td>
				</tr>
				<tr>
					<td th:text="#{ourModel}">我司型号</td>
					<td>
						<input class="easyui-textbox" name="ourModel">
					</td>
					<td th:text="#{custModel}">买家型号</td>
					<td>
						<input class="easyui-textbox" name="custModel">
					</td>
				</tr>
				<tr>
					<td th:text="#{screen}">配屏</td>
					<td>
						<input class="easyui-textbox" name="screen">
					</td>
					<td th:text="#{sold.country}">销往国家</td>
					<td>
						<input class="easyui-textbox" name="soldToCountry">
					</td>
				</tr>
				<tr>
					<td id="td_cs_title">客服专员名称</td>
					<td id="td_cs_content">
						<input class="easyui-textbox" name="csCodeName">
					</td>
				</tr>
			</table>
		</form>
	</div>

	<!-- 反馈供应商 -->
	<div id="ww-feedback-suplier" class="easyui-dialog dlgForm1" data-options="height:300,closed:true">
		<form method="post" action="panel/cscpt/feedbackSupplier">
			<input type="hidden" name="ids">
			<table>
				<tr>
					<td th:text="#{brand}">品牌</td>
					<td>
						<input class="easyui-combobox" id="vendorCode" name="vendorCode" data-options="valueField:'vendorCode',textField:'brand',url:'archives/vendor/selVendor?isValid=1',required:true,panelHeight:300">
					</td>
				</tr>
				<tr>
					<td th:text="#{remark}">备注</td>
					<td>
						<input class="easyui-textbox" style="height: 60px" name="remark" data-options="multiline:true,required:true">
					</td>
				</tr>
			</table>
		</form>
	</div>

	<div id="ww-closed" class="easyui-dialog dlgForm1" data-options="height:300,closed:true">
		<form method="post" action="panel/cscpt/closedVendorFormStatus">
			<input type="hidden" name="complaintId">
			<table>
				<tr>
					<td>关闭备注</td>
					<td>
						<input class="easyui-textbox" style="height: 60px" name="logRemark" data-options="multiline:true,required:true">
					</td>
				</tr>
				<tr id="logRemark2Td">
					<td>供应商反馈备注</td>
					<td>
						<input class="easyui-textbox" style="height: 60px" id="logRemark2" data-options="multiline:true,disabled:true">
					</td>
				</tr>
			</table>
		</form>
	</div>

	<div th:replace="panel/cs/csCptView::csCpt" />
	<div id="fileDialog" />
</body>
</html>